/**
 * amis v6.13.0
 * build time: 2025-08-12
 * Copyright 2018-2025 baidu
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _Badge = require('amis-ui/lib/components/Badge');
var tslib = require('tslib');
var React = require('react');
var amisCore = require('amis-core');
var QuickEdit = require('../QuickEdit.js');
var Copyable = require('../Copyable.js');
var PopOver = require('../PopOver.js');
var mobxReact = require('mobx-react');
var omit = require('lodash/omit');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _Badge__default = /*#__PURE__*/_interopDefaultLegacy(_Badge);
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
var _J$F_ = (__react_jsx__["default"] || __react_jsx__).Fragment;


;var TableCell = /** @class */function (_super) {
  tslib.__extends(TableCell, _super);
  function TableCell() {
    var _this = _super !== null && _super.apply(this, arguments) || this;
    _this.propsNeedRemove = [];
    return _this;
  }
  TableCell.prototype.render = function () {
    var _a = this.props,
      cx = _a.classnames,
      className = _a.className,
      classNameExpr = _a.classNameExpr,
      render = _a.render,
      _b = _a.style,
      style = _b === void 0 ? {} : _b,
      Component = _a.wrapperComponent,
      contentsOnly = _a.contentsOnly,
      column = _a.column,
      value = _a.value,
      data = _a.data,
      children = _a.children,
      width = _a.width,
      align = _a.align,
      vAlign = _a.vAlign,
      innerClassName = _a.innerClassName,
      label = _a.label,
      tabIndex = _a.tabIndex,
      onKeyUp = _a.onKeyUp,
      rowSpan = _a.rowSpan,
      _body = _a.body,
      tpl = _a.tpl,
      remark = _a.remark,
      cellPrefix = _a.cellPrefix,
      cellAffix = _a.cellAffix,
      isHead = _a.isHead,
      colIndex = _a.colIndex,
      row = _a.row,
      showBadge = _a.showBadge,
      itemBadge = _a.itemBadge,
      textOverflow = _a.textOverflow,
      testIdBuilder = _a.testIdBuilder,
      rest = tslib.__rest(_a, ["classnames", "className", "classNameExpr", "render", "style", "wrapperComponent", "contentsOnly", "column", "value", "data", "children", "width", "align", "vAlign", "innerClassName", "label", "tabIndex", "onKeyUp", "rowSpan", "body", "tpl", "remark", "cellPrefix", "cellAffix", "isHead", "colIndex", "row", "showBadge", "itemBadge", "textOverflow", "testIdBuilder"]);
    if (isHead) {
      Component = 'th';
    } else {
      Component = Component || 'td';
    }
    var isTableCell = Component === 'td' || Component === 'th';
    var schema = tslib.__assign(tslib.__assign({}, column), {
      // 因为列本身已经做过显隐判断了，单元格不应该再处理
      visibleOn: '',
      hiddenOn: '',
      visible: true,
      hidden: false,
      style: column.innerStyle,
      className: innerClassName,
      type: column && column.type || 'plain'
    });
    // 如果本来就是 type 为 button，不要删除，其他情况下都应该删除。
    if (schema.type !== 'button' && schema.type !== 'dropdown-button') {
      delete schema.label;
    }
    var body = children ? children : render('field', schema, tslib.__assign(tslib.__assign({}, omit__default["default"](rest, Object.keys(schema), this.propsNeedRemove)), {
      // inputOnly 属性不能传递给子组件，在 SchemaRenderer.renderChild 中处理掉了
      inputOnly: true,
      value: value,
      data: data
    }));
    if (isTableCell) {
      // table Cell 会用 colGroup 来设置宽度，这里不需要再设置
      // 同时剔除style中的定位相关样式，避免表格样式异常
      style = omit__default["default"](style, ['width', 'position', 'display']);
    } else if (width) {
      style = tslib.__assign(tslib.__assign({}, style), {
        width: style && style.width || width
      });
    }
    if (align) {
      style = tslib.__assign(tslib.__assign({}, style), {
        textAlign: align
      });
    }
    if (vAlign) {
      style = tslib.__assign(tslib.__assign({}, style), {
        verticalAlign: vAlign
      });
    }
    if (column.backgroundScale) {
      var backgroundScale = column.backgroundScale;
      var min = backgroundScale.min;
      var max = backgroundScale.max;
      if (amisCore.isPureVariable(min)) {
        min = amisCore.resolveVariableAndFilter(min, data, '| raw');
      }
      if (amisCore.isPureVariable(max)) {
        max = amisCore.resolveVariableAndFilter(max, data, '| raw');
      }
      if (typeof min === 'undefined') {
        min = Math.min.apply(Math, tslib.__spreadArray([], tslib.__read(data.rows.map(function (r) {
          return r[column.name];
        })), false));
      }
      if (typeof max === 'undefined') {
        max = Math.max.apply(Math, tslib.__spreadArray([], tslib.__read(data.rows.map(function (r) {
          return r[column.name];
        })), false));
      }
      var colorScale = new amisCore.ColorScale(min, max, backgroundScale.colors || ['#FFEF9C', '#FF7127']);
      var value_1 = data[column.name];
      if (amisCore.isPureVariable(backgroundScale.source)) {
        value_1 = amisCore.resolveVariableAndFilter(backgroundScale.source, data, '| raw');
      }
      var color = colorScale.getColor(Number(value_1)).toHexString();
      style.background = color;
    }
    if (contentsOnly) {
      return body;
    }
    return _J$X_(Component, tslib.__assign({
      rowSpan: rowSpan > 1 ? rowSpan : undefined,
      style: style,
      className: cx(className),
      tabIndex: tabIndex,
      onKeyUp: onKeyUp
    }, testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild('cell').getTestId()), showBadge ? _J$X_(_Badge__default["default"], {
      classnames: cx,
      badge: tslib.__assign(tslib.__assign({}, itemBadge), {
        className: cx("Table-badge", itemBadge === null || itemBadge === void 0 ? void 0 : itemBadge.className)
      }),
      data: row.data
    }) : null, cellPrefix, textOverflow === 'ellipsis' ? _J$X_("div", {
      className: cx("TableCell-ellipsis")
    }, body) : body, cellAffix);
  };
  TableCell.defaultProps = {
    wrapperComponent: 'td'
  };
  TableCell.propsList = ['type', 'label', 'column', 'body', 'tpl', 'rowSpan', 'remark', 'contentsOnly'];
  return TableCell;
}(React__default["default"].Component);
var TableCellRenderer = /** @class */function (_super) {
  tslib.__extends(TableCellRenderer, _super);
  function TableCellRenderer() {
    return _super !== null && _super.apply(this, arguments) || this;
  }
  TableCellRenderer.propsList = tslib.__spreadArray(['quickEdit', 'quickEditEnabledOn', 'popOver', 'copyable', 'inline'], tslib.__read(TableCell.propsList), false);
  TableCellRenderer = tslib.__decorate([amisCore.Renderer({
    type: 'cell',
    name: 'table-cell'
  }), PopOver.HocPopOver({
    targetOutter: true
  }), QuickEdit.HocQuickEdit(), Copyable.HocCopyable(), mobxReact.observer], TableCellRenderer);
  return TableCellRenderer;
}(TableCell);
var FieldRenderer = /** @class */function (_super) {
  tslib.__extends(FieldRenderer, _super);
  function FieldRenderer() {
    return _super !== null && _super.apply(this, arguments) || this;
  }
  FieldRenderer.defaultProps = tslib.__assign(tslib.__assign({}, TableCell.defaultProps), {
    wrapperComponent: 'div'
  });
  FieldRenderer = tslib.__decorate([amisCore.Renderer({
    type: 'field',
    name: 'field'
  }), PopOver.HocPopOver(), Copyable.HocCopyable()], FieldRenderer);
  return FieldRenderer;
}(TableCell);

exports.FieldRenderer = FieldRenderer;
exports.TableCell = TableCell;
exports.TableCellRenderer = TableCellRenderer;
